﻿using System;
using System.IO;

namespace WikiDoc.Parser
{
    /// <summary>
    /// 
    /// </summary>
    public class CodeParser : IParser
    {
        /// <summary>
        /// Gets the name.
        /// </summary>
        /// <value>The name.</value>
        public string Name
        {
            get { return "code"; }
        }

        /// <summary>
        /// Processes the specified parser.
        /// </summary>
        /// <param name="argv">The argv.</param>
        /// <param name="reader">The reader.</param>
        /// <param name="formatter">The formatter.</param>
        public void Process(string argv, TextReader reader, IFormatter formatter)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            if (formatter == null)
            {
                throw new ArgumentNullException("formatter");
            }
            
            formatter.BeginTag("code");

            bool started = false;
            string line;

            while ( (line = reader.ReadLine()) != null)
            {
                if (started)
                {
                    formatter.AppendContent(line);
                }
                else
                {
                    started = true;
                    formatter.AppendContent(line);
                }
            }

            formatter.EndTag("code");

        }
    }
}